<template>
  <BaseMainSlot>
    <template v-slot:searchbox>
      <div class="seach-box">
        <div class="select-box-content">
          <div class="select-box-content-name">设备名称：</div>
          <el-input
            v-model="equipmentName"
            clearable
            placeholder="请输入设备名称"
            @change="queryPageList()"
          />
        </div>
      </div>
    </template>
    <template v-slot:content>
      <e-table
        ref="tableData"
        :table-data="tableData"
        :table-columns="tableLabel"
        :page="currentPage"
        :size="pageSize"
        :total="totalSize"
        :loading="loading"
        @sizeChange="changePageSize"
        @pageChange="changeCurrentPage"
        rowKey="repairRecordCode"
        :expandRowKeys="expands"
        :showSelectColumn="false"
        @handleExpandChange="queryRepairHistory"
        @tableUpdatePlus="mixTableUpdatePlus"
      >
        <template slot="expand">
          <el-table
            v-loading="loading"
            :data="repairHistoryList"
            stripe
            border
            style="position: relative"
            height="100px"
            max-height="500px"
          >
            <el-table-column type="index" label="序号" width="50" />
            <el-table-column prop="hitchTypeName" label="故障类型名称" />
            <el-table-column prop="equipmentName" label="设备名称" />
            <el-table-column prop="hitchKeywordNames" label="故障关键字">
              <template slot-scope="scoped">
                <div class="table-btns-box">
                  <div
                    v-if="scoped.row.repairRecordCode"
                    class="table-btns query-btns"
                    @click="queryKey(scoped.row)"
                  >查看关键字</div>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="pictures" label="故障图片">
              <template slot-scope="scoped">
                <div class="table-btns-box">
                  <div
                    v-if="scoped.row.repairRecordCode"
                    class="table-btns query-btns"
                    @click="queryPicture(scoped.row)"
                  >查看图片</div>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="videos" label="故障视频">
              <template slot-scope="scoped">
                <div class="table-btns-box">
                  <div
                    v-if="scoped.row.repairRecordCode"
                    class="table-btns query-btns"
                    @click="queryVideo(scoped.row)"
                  >查看视频</div>
                </div>
              </template>
            </el-table-column>
            <el-table-column prop="taskStatus" label="维修结果" />
            <el-table-column type="expand" label="损耗备件" width="150">
              <template
                v-if="scoped.row.repairConsumeVOList.length > 0"
                slot-scope="scoped"
              >
                <el-table
                  v-loading="loading"
                  :data="scoped.row.repairConsumeVOList"
                  stripe
                  border
                  style="position: relative"
                >
                  <el-table-column type="index" label="序号" width="50" />
                  <el-table-column prop="deviceName" label="备件名称" />
                  <el-table-column prop="num" label="数量" />
                  <el-table-column prop="cost" label="费用" />
                </el-table>
              </template>
            </el-table-column>
            <el-table-column prop="handUsername" label="维修人" />
          </el-table>
        </template>
      </e-table>
      <Video
        :title-text="titleText"
        :edit-object="editObject"
        :show.sync="showVideoDialog"
        @closeDialog="closeDialog"
        @cancelDialog="cancel"
      />
      <Picture
        :title-text="titleText"
        :edit-object="editObject"
        :show.sync="showPictureDialog"
        @closeDialog="closeDialog"
        @cancelDialog="cancel"
      />
      <Key
        :title-text="titleText"
        :edit-object="editObject"
        :show.sync="showKeyDialog"
        @closeDialog="closeDialog"
        @cancelDialog="cancel"
      />
    </template>
  </BaseMainSlot>
</template>

  <script>
import equipStandingBookApi from "@/api/equip-manage/equip-standing-book";
import repairHistoryApi from "@/api/equip-repair-manage/repair-history";
import Video from "@/components/detailDialog/video-dialog.vue";
import Picture from "@/components/detailDialog/picture-dialog.vue";
import Key from "@/components/detailDialog/key-dialog.vue";
import BaseMainSlot from "@/components/BaseMainSlot/kong-new.vue";
import { mymixin } from "@/utils/mixin";

export default {
  name: "EquipLifeCycleReport",
  components: { BaseMainSlot, Video, Picture, Key },
  mixins: [mymixin],
  data() {
    return {
      tableData: [],
      // 所搜条件：设备名称
      equipmentName: "",
      // 所搜条件：选择时间
      generationTime: "",
      startTime: "",
      endTime: "",
      //维修记录
      repairHistoryList: [],
      expands: [], //只展开当前行,放入当前行id
      tableLabel: [
        {
          label: "设备名称",
          param: "equipmentName",
          show: true,
          notSearch: true,
        },
        {
          label: "设备编号",
          param: "equipmentCode",
          show: true,
          notSearch: true,
        },
        {
          label: "购置时间",
          param: "purchaseDate",
          type: "date",
          show: true,
          notSearch: true,
        },
        {
          label: "质保日期",
          param: "warrantyDate",
          type: "date",
          show: true,
          notSearch: true,
        },
        {
          label: "维修次数",
          param: "repairCount",
          show: true,
          notSearch: true,
        },
        {
          label: "维修记录",
          param: "repairCount",
          show: true,
          slotName: "expand",
          type: "expand",
          notSearch: true,
          width: "200",
        },
        {
          label: "损毁时间",
          param: "destroyDate",
          type: "datetime",
          notSearch: true,
          show: true,
        },
      ],
    };
  },
  watch: {},
  created() {
    this.queryPageList();
  },
  mounted() {},
  methods: {
    //查询设备维修记录
    queryRepairHistory(row, expandedRows) {
      console.log(row, expandedRows);
      let that = this;
      let param = {
        page: 1,
        size: 1000,
        entity: {
          equipmentCode: row.equipmentCode,
        },
      };
      repairHistoryApi.queryPageList(param).then((res) => {
        this.repairHistoryList = res.data.content;
        // 每次只展开一行
        if (expandedRows.length) {
          that.expands = [];
          if (row) {
            that.expands.push(row.equipmentCode);
          }
        } else {
          that.expands = [];
        }
      });
    },
    queryPageList(e) {
      this.loading = false;
      let params = {
        page: this.currentPage,
        size: this.pageSize,
      };
      let entity = { ...e };
      if (this.equipmentName) {
        entity.equipmentName = this.equipmentName;
      }
      params.entity = entity;
      equipStandingBookApi.queryReportForm(params).then((res) => {
        this.loading = false;
        if (res.code === 1) {
          let data = res.data;
          this.totalSize = data.total;
          data.content.forEach((item) => {
            item.rowKey = item.equipmentCode;
          });
          this.tableData = data.content;
          this.addblankmet();
          this.resetActionBar();
        }
      });
    },
    // 查看关键字
    queryKey(row) {
      this.titleText = "关键字";
      this.editObject = JSON.parse(JSON.stringify(row));
      this.showKeyDialog = true;
    },
    // 查看视频
    queryVideo(row) {
      this.titleText = "故障视频";
      this.editObject = JSON.parse(JSON.stringify(row));
      this.showVideoDialog = true;
    },
    // 查看图片
    queryPicture(row) {
      this.titleText = "故障图片";
      this.editObject = JSON.parse(JSON.stringify(row));
      this.showPictureDialog = true;
    },
    // changePageSize(pageSize) {
    //   if (this.topitemtypeId === "任务") {
    //     this.pageSize = pageSize;
    //   }
    //   if (this.topitemtypeId === "异常任务") {
    //     this.anPageSize = pageSize;
    //   }
    //   this.queryList();
    // },
    // changeCurrentPage(currentPage) {
    //   if (this.topitemtypeId === "任务") {
    //     this.currentPage = currentPage;
    //   }
    //   if (this.topitemtypeId === "异常任务") {
    //     this.anCurrentPage = currentPage;
    //   }
    //   this.queryList();
    // },
    // 修改
    edit(row) {
      if (row.taskId) {
        this.showAddEditDialog = true;
        this.editObject = JSON.parse(JSON.stringify(row));
      }
    },
  },
};
</script>

  <style lang="scss" scoped>
::v-deep .el-table {
  .el-icon {
    color: #fff;
  }
  .el-table__expanded-cell {
    background: #4affda00;
  }
}
</style>
